// +build js,wasm

package jsgo

import (
	"errors"
	"syscall/js"
)

func Q(arg interface{}) *JsDom {
	switch arg.(type) {
	case string:
		return &JsDom{JsObject{
			value: js.Global().Get("document").Call("querySelectorAll", arg.(string)),
		}}
	case func():
		js.Global().Call(
			"addEventListener",
			"load",
			js.FuncOf(func(this js.Value, args []js.Value) interface{} {
				arg.(func())()
				return js.Global()
			}))
		return nil
	case js.Func:
		js.Global().Call("addEventListener", "load", arg)
		return nil
	case js.Value:
		return &JsDom{JsObject{
			value: arg.(js.Value),
		}}
	default:
		panic(errors.New("invalid arg type"))
	}
}
